package com.cysion.study.ui.fragment

import android.support.v7.widget.LinearLayoutManager
import android.view.View
import com.cysion.study.ktbox.base.BaseFragment
import com.cysion.study.ktbox.net.BaseResponseRx
import com.cysion.study.ktbox.net.ErrorHandler
import com.cysion.study.ktbox.utils.CLog
import com.cysion.other.startActivity_ex
import com.cysion.targetfun._subscribe
import com.cysion.study.uibox.dialog.Alert
import com.cysion.study.R
import com.cysion.study.adapter.LeveManageOkAdapter
import com.cysion.study.adapter.LeveManageOkAdapter.Companion.look
import com.cysion.study.helper.UserCache
import com.cysion.study.net.ApiClient
import com.cysion.study.ui.LeveManageDetailActivity
import com.cysion.study.widget.ShowToast
import com.scwang.smartrefresh.layout.constant.RefreshState
import kotlinx.android.synthetic.main.fragment_leve_manage_ok.*

/**
 * 普通教师-考级管理-课程管理
 * Created by chu on 2019-06-30.
 */
class LeveManageOkFragment:BaseFragment(), View.OnClickListener {

    private lateinit var classAdapter: LeveManageOkAdapter
    private var mSourceList: MutableList<String> = mutableListOf()
    override fun getLayoutId(): Int {
        return R.layout.fragment_leve_manage_ok
    }

    override fun initView() {

        initRecyclerView()
        initRefreshLayout()


    }



    var type = "0"

    override fun onClick(v: View?) {
        when (v?.id) {
            R.id.tab1 -> {//请假

                type = "0"
            }
            R.id.tab2 -> {//报销
                type = "1"

            }
        }

    }




    private var curPage = 1

    private fun initRecyclerView() {
        rv_list.isNestedScrollingEnabled=false
        classAdapter= LeveManageOkAdapter(mSourceList,context)
        rv_list.adapter=classAdapter
        rv_list.layoutManager=LinearLayoutManager(context)

        classAdapter.setOnTypeClickListener { obj, position, flag ->
            if (flag == look) {
//                ShowToast("查看课表")
                context.startActivity_ex<LeveManageDetailActivity>()//查看考核详情
            }
        }

    }

    //    初始化刷新控件
    private fun initRefreshLayout() {
//        smartLayout.setEnableLoadMore(false)
        smartLayout.setOnRefreshListener {
//            getDataList(curPage)
            smartLayout.setEnableLoadMore(true)
        }
        smartLayout.setOnLoadMoreListener {

//            getDataList(curPage)
        }

        if (classAdapter.itemCount == 0) {
            var lists: MutableList<String> = mutableListOf("","")
            mSourceList.addAll(lists)
            classAdapter.notifyDataSetChanged()
        }
    }

    override fun initData() {
        super.initData()
        smartLayout.autoRefresh()
    }







    private fun stopRefresh() {
        if (smartLayout.state == RefreshState.Refreshing) {
            smartLayout.finishRefresh()
        } else if (smartLayout.state == RefreshState.Loading) {
            smartLayout.finishLoadMore(100)
        }
    }



    override fun closeMvp() {
    }
}